//
//  TEHTTPRequestViewController.m
//  TintExample
//
//  Created by Kevin Wu on 9/3/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TEHTTPRequestViewController.h"

@implementation TEHTTPRequestViewController


#pragma mark - Memory

- (id)init
{
    self = [super init];
    if ( self ) {
        _test = [TEHTTPRequestTest sharedObject];
    }
    return self;
}

- (void)dealloc
{
    _test = nil;
    TTRelease(_infoLabel);
    [super dealloc];
}


#pragma mark - UIViewController

- (void)loadView
{
    [super loadView];
    
    [self addButtonWithTitle:@"start" selector:@selector(start:)];
    [self addButtonWithTitle:@"stop" selector:@selector(stop:)];
    [self addButtonWithTitle:@"show" selector:@selector(show:)];
    
    UILabel *label = nil;
    
    label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:12.0];
    label.textColor = [UIColor blackColor];
    label.lineBreakMode = UILineBreakModeTailTruncation;
    label.numberOfLines = 1;
    label.textAlignment = UITextAlignmentCenter;
    label.adjustsFontSizeToFitWidth = NO;
    label.backgroundColor = [UIColor clearColor];
    [self.view addSubview:label];
    _infoLabel = label;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [_infoLabel setFrameIfNeeded:TTRectMake(0.0, 100.0, 320.0, 44.0)];
}


#pragma mark - Public

- (void)start:(id)sender
{
    [_test startTest];
}

- (void)stop:(id)sender
{
    [_test stopTest];
}

- (void)show:(id)sender
{
    _infoLabel.text = [NSString stringWithFormat:@"%d - %d = %d", _test.added, _test.removed, [_test.loadingList count]];
}


@end
